﻿using System;
using System.Windows.Forms;
using MapWindow.Map;
using MapWindow.Components;
using MapWindow.PluginInterfaces;

namespace SamplePluginCS
{
    [MapWindowPlugin("SamplePluginCS", Author="JK", UniqueName="SamplePluginCS_1", Version="1.0")]
    public class Class1 : Extension, IMapPlugin
    {
        #region Variables

        private IMapPluginArgs _mapWin;
        private ToolStripMenuItem menuItem1;

        #endregion

        #region IMapPlugin Members

        //when the plug-in is activated
        public void Initialize(IMapPluginArgs args)
        {
            _mapWin = args;
            
            //add a new menu item
            menuItem1 = new ToolStripMenuItem("Sample Plug-in c#");
            ToolStripMenuItem menuItem2 = new ToolStripMenuItem("Menu Item 2");
            menuItem1.DropDownItems.Add(menuItem2);
            _mapWin.MainMenu.Items.Add(menuItem1);

            //add a new tab control
            MyControl1 myControl = new MyControl1();
            _mapWin.PanelManager.AddPanel(myControl, "SamplePlugin1", Images.graph);

            //handle the menu item click event
            menuItem2.Click += new EventHandler(menuItem2_Click);
        }
        
        #endregion

        #region Extension Members

        //when the plug-in is deactivated
        protected override void OnDeactivate()
        {
            //remove the menu item
            if (_mapWin.MainMenu.Items.Contains(menuItem1))
            {
                _mapWin.MainMenu.Items.Remove(menuItem1);
                _mapWin.PanelManager.RemovePanel("SamplePlugin1");
            }
        }

        #endregion

        #region Event Handlers

        //when the menu item is clicked
        void menuItem2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You clicked menu item 2.");
        }

        #endregion
    }
}
